package com.common.stdlib
{
	import flash.utils.*;

	/**
	 *内存类 
	 * @author lxh
	 * 
	 */	
	public class Memory
	{
		/**
		 *拷贝内存 
		 * @param dst
		 * @param src
		 * @param length
		 * @param dst_offset
		 * @param src_offset
		 * 
		 */		
		public static function copyMemory(dst:ByteArray,src:ByteArray,length:uint = 0,
							dst_offset:uint = 0, src_offset:uint = 0):void 
		{
			var old_pos:int = src.position;
			src.position = src_offset;
			src.readBytes(dst,dst_offset,length);
			src.position = old_pos;
		}
		/**
		 *移动内存字节流 
		 * @param dst
		 * @param src
		 * @param length
		 * @param dst_offset
		 * @param src_offset
		 * 
		 */		
		public static function moveMemory(dst:ByteArray,src:ByteArray,length:uint = 0,
							dst_offset:uint = 0, src_offset:uint = 0):void
		{
			var old_pos:int = src.position;
			src.position = src_offset;
			src.readBytes(dst,dst_offset,length);
			src.position = old_pos;
		}
		/**
		 *设置内存字节流 
		 * @param dst
		 * @param val
		 * @param size
		 * @param pos
		 * 
		 */		
		public static function setMemory(dst:ByteArray,val:int,size:int,pos:int=0):void 
		{
			var old_pos:int = dst.position;
			dst.position = pos;
			for (var i:int = 0; i < size; i ++) 
			{
				dst.writeByte(val);
			}
			dst.position = old_pos;
		}
		/**
		 *设置内存字节流通过内存字节流 
		 * @param dst
		 * @param val
		 * @param length
		 * @param dst_offset
		 * @param val_offset
		 * 
		 */		
		public static function setMemoryByByteArray(dst:ByteArray,val:ByteArray,length:uint = 0,
								   dst_offset:uint = 0, val_offset:uint = 0):void 
		{
			var old_pos:int = dst.position;
			dst.position = dst_offset;
			var old_pos1:int = val.position;
			val.position = val_offset;
			
			dst.writeBytes(val,val_offset,length);
		
			val.position = old_pos1;
			dst.position = old_pos;
		}
		
		/**
		 *获取高字节 
		 * @param w
		 * @return 
		 * 
		 */		
		public static function HIBYTE(w:uint):uint
		{
			return (w & 0x0000ff00) >> 8;
		}
		/**
		 *获取低字节 
		 * @param w
		 * @return 
		 * 
		 */		
		public static function LOBYTE(w:uint):uint
		{
			return (w & 0x000000ff);
		}
		/**
		 *判断大小 
		 * @param a
		 * @param b
		 * @return 
		 * 
		 */		
		public static function __min(a:*,b:*):*
		{
			return (((a) < (b)) ? (a) : (b));
		}
		/**
		 *判断大小 
		 * @param a
		 * @param b
		 * @return 
		 * 
		 */		
		public static function __max(a:*,b:*):*
		{
			return (((a) > (b)) ? (a) : (b));
		}

		public function Memory()
		{
		}

	}
}